// led_driver.h
#ifndef LED_DRIVER_H
#define LED_DRIVER_H

#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <string.h>
#include "driver/ledc.h"

#define NET_LED_GPIO GPIO_NUM_40
#define GPS_LED_GPIO GPIO_NUM_39

#define LEDC_TIMER              LEDC_TIMER_0
#define LEDC_MODE               LEDC_LOW_SPEED_MODE
#define LEDC_CHANNEL_NET        LEDC_CHANNEL_0
#define LEDC_CHANNEL_GPS        LEDC_CHANNEL_1
#define LEDC_DUTY_RES           LEDC_TIMER_13_BIT // 13位分辨率
#define LEDC_FREQUENCY          (5000) // 5kHz

typedef enum {
    LED_NET_STATE,
    LED_GPS_STATE
} led_type_t;

typedef enum {
    LED_OFF,
    LED_SLOW_BLINK, // 1Hz - 系统待机
    LED_FAST_BLINK, // 5Hz - 采集异常
    LED_ON,         // 持续亮 - 数据发送中
    LED_BREATH      // 呼吸灯效果
} led_state_t;

typedef struct {
    led_state_t state;
    TickType_t last_toggle;
    bool current_level;
    ledc_channel_t channel; // PWM通道
    int breath_direction;   // 呼吸灯方向：1表示渐亮，-1表示渐暗
    int breath_duty;        // 当前占空比
} led_control_t;

// 初始化函数
void led_init(void);

// 状态设置
void led_set_state(led_type_t led, led_state_t state);

// 任务安全控制
void led_task_start(void);
void led_task_stop(void);

#endif // LED_DRIVER_H